# -*- coding: utf-8 -*-

from PyQt4 import QtGui,QtCore
from logon_dlg import Ui_logon_dlg
from logic import thread_msgs

class LogonUI(QtCore.QObject):
    def __init__(self, logicthread):
        QtCore.QObject.__init__(self)
        self.logicthread = logicthread
        self.dlg = QtGui.QDialog()
        self.logon_dlg = Ui_logon_dlg()
        self.logon_dlg.setupUi(self.dlg)
        self.dlg.setModal(False)
        flags=QtCore.Qt.WindowMinMaxButtonsHint 
        self.dlg.setWindowFlags(flags)      
        
        self.dlg.show()        
        self.logon_dlg.edit_deviceid.setText(u'moblove_pytest_100')
        #self.logon_dlg.edit_deviceid.setDisabled(True)
        self.logon_dlg.edit_email.setText(u'cindy_1')
        self.logon_dlg.edit_email_end.setText(u'cindy_10')
        self.logon_dlg.btn_logon.clicked.connect(self.on_logon_clicked)        
        QtCore.QObject.connect(self,QtCore.SIGNAL("logic_logon_success_sig()"), self.logic_logon_success_slot)
        QtCore.QObject.connect(self,QtCore.SIGNAL("logic_logon_failed_sig()"), self.logic_logon_failed_slot)        
        self.logon_dlg.btn_register.clicked.connect(self.on_register_clicked)
        #self.logon_dlg.btn_register.setDisabled(True)
        self.cfgusers = None
                
    def on_logon_clicked(self):
        deviceid = self.logon_dlg.edit_deviceid.displayText().toUtf8()
        begin = self.logon_dlg.edit_email.displayText().toUtf8()
        end = self.logon_dlg.edit_email_end.displayText().toUtf8()
        self.logicthread.post_msg(thread_msgs.BatchMsgLogon(begin, end))
        
    def on_register_clicked(self):
        deviceid = self.logon_dlg.edit_deviceid.displayText().toUtf8()
        self.logicthread.post_msg(thread_msgs.MsgRegister(deviceid))
        
    def logic_logon_success(self):
        #self.emit(QtCore.SIGNAL('logic_logon_success_sig()'))
        pass        
    
    def logic_logon_failed(self):
        #self.emit(QtCore.SIGNAL('logic_logon_failed_sig()'))
        pass
    
    def logic_logon_success_slot(self):
        self.logon_dlg.btn_logon.setText(u"已登陆")
        self.dlg.hide()                
    
    def logic_logon_failed_slot(self):
        self.logon_dlg.btn_logon.setText(u"登陆")
        self.logon_dlg.btn_logon.setEnabled(True)
        self.dlg.show()
       
               
        
        
        